package com.example.a14874.listviewtraining;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    private ListView nameListView;
    private String[] nameArr = {"张三","李四","张三","李四"};
    private ArrayList<Student> studentArrayList = new ArrayList<>();
    private myadapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initStuList();
        nameListView = findViewById(R.id.name_ListView);

        adapter = new myadapter(MainActivity.this,studentArrayList);

        nameListView.setAdapter(adapter);

    }
    private void initStuList(){
        Student s1 = new Student(R.drawable.dog1,"张三",18);
        Student s2 = new Student(R.drawable.dog1,"张是",19);
        Student s3 = new Student(R.drawable.dog1,"张发",10);
        Student s4 = new Student(R.drawable.dog1,"张吧",11);
        Student s5 = new Student(R.drawable.dog1,"张把",13);
        studentArrayList.add(s1);
        studentArrayList.add(s2);
        studentArrayList.add(s3);
        studentArrayList.add(s4);
        studentArrayList.add(s5);
    }
}
